package com.vcredit.creditcat.web.app;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vcredit.creditcat.api.IZmxyProcessManager;
import com.vcredit.creditcat.dto.zmxy.ZmxyCallBackDto;
import com.vcredit.creditcat.dto.zmxy.ZmxyQueryDto;
import com.vcredit.creditcat.exception.CreditParamInvalidException;
import com.vcredit.creditcat.model.Cust;
import com.vcredit.framework.annotation.Log;

@RestController
@RequestMapping(value = "/zmxy")
public class ZmxyProcessController extends BaseCreditCatController {

	@Reference(version = "1.0")
	private IZmxyProcessManager zmxyProcessManager;

	/**
	 * 芝麻信用回调,form提交
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@Log
	@RequestMapping(value = "/zmxyCallBack")
	public ZmxyCallBackDto zmxyCallBack(HttpServletRequest request) throws Exception {
		String params = request.getParameter("params");
		String sign = request.getParameter("sign");
		if (StringUtils.isBlank(params) || StringUtils.isBlank(sign)) {
			throw new CreditParamInvalidException("参数不能为空");
		}
		return zmxyProcessManager.zmxyCallBack(params, sign);
	}

	/**
	 * 查询芝麻信用
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@Log
	@RequestMapping(value = "/zmxyQuery")
	public ZmxyQueryDto zmxyQuery(HttpServletRequest request) throws Exception {
		Cust cust = getCust(request);
		ZmxyQueryDto response = zmxyProcessManager.zmxyQuery(cust);
		return response;
	}
}
